
<?php

function dal_friend_list($user_id)
{
	$t_conn   = dal_mocool_get_dbconn();
	$t_sql    = 'SELECT friend_id FROM mocool_friend_table WHERE user_id=' . $user_id;
	$t_result = mysql_query($t_sql, $t_conn);
	if (!$t_result) {
		dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
		return null;
	}
	$t_ret = Array();
	while ($row = mysql_fetch_array($t_result, MYSQL_ASSOC)) {
		array_push($t_ret, $row['friend_id']);
	}
	return $t_ret;
}

function dal_friend_insert($user_id, $friend_id, $source)
{
	$t_conn   = dal_mocool_get_dbconn();
	$source   = mysql_escape_string($source);
	$t_sql    = "INSERT INTO mocool_friend_table VALUES($user_id, $friend_id, '$source')";
	$t_result = mysql_query($t_sql, $t_conn);
	if (!$t_result) {
		dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
		return false;
	}
	return true;
}

function dal_friend_remove($user_id, $friend_id)
{
	$t_conn   = dal_mocool_get_dbconn();
	$t_sql    = 'DELETE FROM mocool_friend_table WHERE user_id=' + $user_id + ' AND friend_id=' + $friend_id;
	$t_result = mysql_query($t_sql, $t_conn);
	if (!$t_result) {
		dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
		return false;
	}
	return true;
}

function dal_block_list($token, $time, $user_id, $app, $os, $ip)
{
	$t_conn   = dal_mocool_get_dbconn();
	$t_sql    = 'SELECT friend_id FROM mocool_block_table WHERE user_id=' + $user_id;
	$t_result = mysql_query($t_sql, $t_conn);
	if (!$t_result) {
		dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
		return null;
	}
	$t_ret = Array();
	while ($row = mysql_fetch_array($t_result, MYSQL_ASSOC)) {
		array_push($t_ret, $row['friend_id']);
	}
	return $t_ret;
}

function dal_block_insert($user_id, $friend_id)
{
	$t_conn   = dal_mocool_get_dbconn();
	$t_sql    = "INSERT INTO mocool_block_table VALUES($user_id, $friend_id)";
	$t_result = mysql_query($t_sql, $t_conn);
	if (!$t_result) {
		dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
		return false;
	}
	return true;
}

function dal_block_remove($user_id, $friend_id)
{
	$t_conn   = dal_mocool_get_dbconn();
	$t_sql    = "DELETE FROM mocool_block_table WHERE user_id=$user_id AND friend_id=$friend_id";
	$t_result = mysql_query($t_sql, $t_conn);
	if (!$t_result) {
		dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
		return false;
	}
	return true;
}

?>
